import Picker from 'react-native-picker';
import React, { Component } from 'react'
import {
    View,
    Text,
    Image,
    StyleSheet,
    TextInput,
    TouchableOpacity,
    ScrollView,
    Modal,
} from 'react-native';

import { expedit_Style as styles } from '../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;


const data1 = ['未工作', '在职，看看新机会', '离职，正在找工作', '在职，暂无跳槽打算', '在职，急寻新工作'];
const data2 = ['博士', '硕士', '本科', '大专', '高中', '中专', '初中'];
const data3 = ['不限', '1-2年', '3-5年', '6-10年', '10年以上'];
const data4 = ['国企', '民营', '外企', '政府'];
const t1 = [];
const now = new Date().getFullYear();
for (var i = 1960; i <= now; i++) {
    t1.push(i);
}

export default class ChooseUtil extends Component {

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            isModal: false
        };

        this.picker = Picker;

    }

    initPicker(type) {
        switch (type) {
            case "state":
                this.picker.init({
                    pickerData: data1,
                    selectedValue: ['在职，看看新机会'], //默认值
                    pickerConfirmBtnText: '确认',
                    pickerConfirmBtnColor: [61, 156, 204, 1],
                    pickerCancelBtnText: '取消',
                    pickerCancelBtnColor: [61, 156, 204, 1],
                    pickerTitleText: '选择状态',
                    pickerTitleColor: [61, 156, 204, 1],
                    pickerToolBarBg: [255, 255, 255, 1], //标题背景颜色
                    pickerBg: [255, 255, 255, 1], //内容背景颜色
                    wheelFlex: [1], //布局比例
                    pickerFontColor: [0, 0, 0, 1], //选中颜色
                    onPickerConfirm: data => { //确认触发
                        var str = '';
                        if (data[0] == "未工作") {
                            str = '0';
                        } else if (data[0] == "在职，看看新机会") {
                            str = '1';
                        } else if (data[0] == "离职，正在找工作") {
                            str = '2';
                        } else if (data[0] == "在职，暂无跳槽打算") {
                            str = '3';
                        } else if (data[0] == "在职，急寻新工作") {
                            str = '4';
                        } else {
                            str = null;
                        }
                        this._rollBack({ type: "state", data: str })
                    },
                    onPickerCancel: data => {   //取消触发
                        this.setState({
                            isModal: false
                        });
                    },
                    onPickerSelect: data => {   //选择触发
                    }
                });
                break;

            case "education":
                this.picker.init({
                    pickerData: data2,
                    selectedValue: ['本科'], //默认值
                    pickerConfirmBtnText: '确认',
                    pickerConfirmBtnColor: [61, 156, 204, 1],
                    pickerCancelBtnText: '取消',
                    pickerCancelBtnColor: [61, 156, 204, 1],
                    pickerTitleText: '选择学历',
                    pickerTitleColor: [61, 156, 204, 1],
                    pickerToolBarBg: [255, 255, 255, 1], //标题背景颜色
                    pickerBg: [255, 255, 255, 1], //内容背景颜色
                    wheelFlex: [1], //布局比例
                    pickerFontColor: [0, 0, 0, 1], //选中颜色
                    onPickerConfirm: data => { //确认触发
                        var str = '';
                        if (data[0] == "博士") {
                            str = '博士';
                        } else if (data[0] == "硕士") {
                            str = '硕士';
                        } else if (data[0] == "本科") {
                            str = '本科';
                        } else if (data[0] == "大专") {
                            str = '大专';
                        } else if (data[0] == "高中") {
                            str = '高中';
                        } else if (data[0] == "中专") {
                            str = '中专';
                        } else if (data[0] == "初中") {
                            str = '初中';
                        } else {
                            str = null;
                        }
                        this._rollBack({ type: "education", data: str })
                    },
                    onPickerCancel: data => {   //取消触发
                        this.setState({
                            isModal: false
                        });
                    },
                    onPickerSelect: data => {   //选择触发
                    }
                });

                break;

            case "experience":
                this.picker.init({
                    pickerData: data3,
                    selectedValue: ['不限'], //默认值
                    pickerConfirmBtnText: '确认',
                    pickerConfirmBtnColor: [61, 156, 204, 1],
                    pickerCancelBtnText: '取消',
                    pickerCancelBtnColor: [61, 156, 204, 1],
                    pickerTitleText: '选择工作经验',
                    pickerTitleColor: [61, 156, 204, 1],
                    pickerToolBarBg: [255, 255, 255, 1], //标题背景颜色
                    pickerBg: [255, 255, 255, 1], //内容背景颜色
                    wheelFlex: [1], //布局比例
                    pickerFontColor: [0, 0, 0, 1], //选中颜色
                    onPickerConfirm: data => { //确认触发
                        var str = '';
                        if (data[0] == "不限") {
                            str = '不限';
                        } else if (data[0] == "1-2年") {
                            str = '1-2年';
                        } else if (data[0] == "3-5年") {
                            str = '3-5年';
                        } else if (data[0] == "6-10年") {
                            str = '6-10年';
                        } else if (data[0] == "10年以上") {
                            str = '10年以上';
                        } else {
                            str = null;
                        }
                        this._rollBack({ type: "experience", data: str })
                    },
                    onPickerCancel: data => {   //取消触发
                        this.setState({
                            isModal: false
                        });
                    },
                    onPickerSelect: data => {   //选择触发
                    }
                });

                break;

            case "company":
                this.picker.init({
                    pickerData: data4,
                    selectedValue: ['不限'], //默认值
                    pickerConfirmBtnText: '确认',
                    pickerConfirmBtnColor: [61, 156, 204, 1],
                    pickerCancelBtnText: '取消',
                    pickerCancelBtnColor: [61, 156, 204, 1],
                    pickerTitleText: '选择公司性质',
                    pickerTitleColor: [61, 156, 204, 1],
                    pickerToolBarBg: [255, 255, 255, 1], //标题背景颜色
                    pickerBg: [255, 255, 255, 1], //内容背景颜色
                    wheelFlex: [1], //布局比例
                    pickerFontColor: [0, 0, 0, 1], //选中颜色
                    onPickerConfirm: data => { //确认触发
                        var str = '';
                        if (data[0] == "国企") {
                            str = '国企';
                        } else if (data[0] == "民营") {
                            str = '民营';
                        } else if (data[0] == "外企") {
                            str = '外企';
                        } else if (data[0] == "政府") {
                            str = '政府';
                        } else {
                            str = null;
                        }
                        this._rollBack({ type: "company", data: str })
                    },
                    onPickerCancel: data => {   //取消触发
                        this.setState({
                            isModal: false
                        });
                    },
                    onPickerSelect: data => {   //选择触发
                    }
                });
                break;


            case 'time':
                this.picker.init({
                    pickerData: t1,
                    selectedValue: [2000], //默认值
                    pickerConfirmBtnText: '确认',
                    pickerConfirmBtnColor: [61, 156, 204, 1],
                    pickerCancelBtnText: '取消',
                    pickerCancelBtnColor: [61, 156, 204, 1],
                    pickerTitleText: '选择年份',
                    pickerTitleColor: [61, 156, 204, 1],
                    pickerToolBarBg: [255, 255, 255, 1], //标题背景颜色
                    pickerBg: [255, 255, 255, 1], //内容背景颜色
                    wheelFlex: [1], //布局比例
                    pickerFontColor: [0, 0, 0, 1], //选中颜色
                    onPickerConfirm: data => { //确认触发
                        this._rollBack({ type: "time", data: data[0] })
                    },
                    onPickerCancel: data => {   //取消触发
                        this.setState({
                            isModal: false
                        });
                    },
                    onPickerSelect: data => {   //选择触发
                    }
                });

                break;
            default:
                break;
        }
    }

    showModal() {
        this.picker.show();
        this.setState({
            isModal: true
        })
    }

    onRequestClose() {
        this.picker.hide();
        this.setState({
            isModal: false
        });
    }

    _rollBack(data) {
        if (this.props.rollback) {
            this.props.rollback(data)
        }
        this.setState({
            isModal: false
        })
    }


    render() {
        return (
            <View style={styles.container}>
                {/* 初始化Modal */}
                <Modal
                    animationType='none'           // 从底部滑入
                    transparent={true}             // 不透明
                    visible={this.state.isModal}    // 根据isModal决定是否显示
                    onRequestClose={() => { // android后退按钮实现
                        this.onRequestClose();
                    }}
                >
                    <View style={{ flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.3)' }}></View>
                </Modal>
            </View>
        );
    }
}
